<?php
 
class IFrame extends Page {
 
	// define your database fields here - for example we have author
	static $db = array(
		"remote_url" => "Varchar(1024)",
		"label" => "Varchar(100)",
		"height" => "Varchar(20)",
		"width" => "Varchar(20)",
	);

	static $defaults = array(

	);

	static $icon = "iframe/images/window";

	// add custom fields for this flickr gallery page
	function getCMSFields($cms) {

		$fields = parent::getCMSFields($cms);
		$fields->removeFieldFromTab("Root.Content.Main","Content");
		$fields->addFieldToTab("Root.Content.Main", new TextField("remote_url","Remote URL"));
		$fields->addFieldToTab("Root.Content.Main", new NumericField("height","Height of remote window", "600px"));
		$fields->addFieldToTab("Root.Content.Main", new NumericField("width","Width of remote window", "400px"));
		return $fields;
	}


	function isPost(){
		return Director::urlParam('Action') == 'post';
	}

}

class IFrame_Controller extends Page_Controller {
	function init() {
		if(Director::fileExists(project() . "/css/FlickrGallery.css")) {
			Requirements::css(project() . "/css/FlickrGallery.css");
		} else {
			Requirements::css("flickrservice/css/FlickrGallery.css");
		}
		Requirements::javascript( "flickrservice/javascript/prototype.js" );
		Requirements::javascript( "flickrservice/javascript/effects.js" );
		Requirements::javascript( "flickrservice/javascript/lightwindow.js" );

		Requirements::css("flickrservice/css/lightwindow.css");

		if( $pos = strpos( $_SERVER[ 'HTTP_USER_AGENT' ], 'MSIE' ) ) {
			$version = substr( $_SERVER[ 'HTTP_USER_AGENT' ], $pos + 5, 3 );
			if( $version < 7 ) {
				Requirements::css( "flickrservice/css/lightwindowIE6.css" );
			}
		}

		parent::init();	
	}
   
   	function post(){
		if(!Permission::check('ADMIN')){
			Security::permissionFailure($this,
				"IFrame management is an administrator task. Please log in.");
		}
		return array();
	}

}

?>